using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Meebey.SmartIrc4net;
using System.Collections;
using System.Reflection;

namespace dotIRC
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            this.Text = GetWinTitle();
        }

        private Hashtable _sessions = new Hashtable(); private int _sessionCount = 0;

        public Hashtable treeViewForms = new Hashtable();
        private Form _selectedWindow;

        private string GetWinTitle()
        {
            StringBuilder sb = new StringBuilder();
#if DEBUG
            sb.Append(Program.CODENAME);
#else
            sb.Append(".IRC");
#endif
            sb.Append(" " +
                      Assembly.GetExecutingAssembly().GetName().Version.Major +
                      "." +
                      Assembly.GetExecutingAssembly().GetName().Version.Minor);
#if DEBUG
            sb.Append(" - DEBUG Build");
#endif

            return sb.ToString();
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StatusForm newSession = new StatusForm();
            _sessions.Add(_sessionCount, newSession);
            _sessionCount++;
            newSession.MdiParent = this;
            newSession.Show();
        }

        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ActiveMdiChild != null)
            this.ActiveMdiChild.Close();
        }

        private void windowListTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            _selectedWindow = (Form)treeViewForms[e.Node];
            _selectedWindow.Activate();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            newToolStripMenuItem_Click(sender, e); 
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Program.Settings.Save();
        }
    }
}